﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using JMT.Controls.Commands;

namespace JMT.Controls.ContextMenus
{
    public static class ContextMenuFactory
    {
        private static Dictionary<string, ContextMenu> s_menus = new Dictionary<string, ContextMenu>();

        static ContextMenuFactory()
        {
            s_menus.Add("classbox", CreateClassContextMenu());
            s_menus.Add("interfacebox", CreateClassContextMenu());
            s_menus.Add("diagram", CreateDiagramContextMenu());
            s_menus.Add("solutiontreenode", CreateSolutionTreeNodeContextMenu());
            s_menus.Add("classtreenode", CreateClassTreeNodeContextMenu());
            s_menus.Add("packagetreenode", CreatePackageTreeNodeContextMenu());
        }

        public static ContextMenu Get(string type)
        {
            if (s_menus.ContainsKey(type))
            {
                return s_menus[type];
            }
            return null;
        }

        private static ContextMenu CreateClassContextMenu()
        {
            ContextMenu _classElementCXTMenu = new ContextMenu();
            MenuItem mAddProperty = new MenuItem();
            mAddProperty.Header = "Add Property";
            mAddProperty.Command = new AddPropertyCommand(_classElementCXTMenu, mAddProperty);
            _classElementCXTMenu.Items.Add(mAddProperty);

            MenuItem mAddMethod = new MenuItem();
            mAddMethod.Header = "Add Method";
            mAddMethod.Command = new AddMethodCommand(_classElementCXTMenu, mAddMethod);
            _classElementCXTMenu.Items.Add(mAddMethod);

            _classElementCXTMenu.Items.Add(new Separator());

            MenuItem deleteMenu = new MenuItem();
            deleteMenu.Header = "Delete";
            deleteMenu.Command = new DeleteUIClassCommand(_classElementCXTMenu, mAddMethod);
            _classElementCXTMenu.Items.Add(deleteMenu);

            return _classElementCXTMenu;
        }

        private static ContextMenu CreateDiagramContextMenu()
        {
            ContextMenu _cxtMenuDiagram = new ContextMenu();

            MenuItem mAddInterface = new MenuItem();
            mAddInterface.Header = "Add Interface";
            mAddInterface.Command = new AddUIInterfaceCommand(_cxtMenuDiagram, mAddInterface);
            _cxtMenuDiagram.Items.Add(mAddInterface);

            MenuItem mAddClass = new MenuItem();
            mAddClass.Header = "Add Class";
            mAddClass.Command = new AddUIClassCommand(_cxtMenuDiagram, mAddClass);
            _cxtMenuDiagram.Items.Add(mAddClass);

            MenuItem caiClass = new MenuItem();
            caiClass.Header = "Copy As Image";
            caiClass.Command = new CopyToImageCommand(_cxtMenuDiagram, caiClass);
            _cxtMenuDiagram.Items.Add(caiClass);

            return _cxtMenuDiagram;
        }

        private static ContextMenu CreateSolutionTreeNodeContextMenu()
        {
            ContextMenu cxtmNodeSolution = new ContextMenu();

            MenuItem cxtmNodeSolutionNode0 = new MenuItem();
            cxtmNodeSolutionNode0.Header = "Add Diagram";
            cxtmNodeSolutionNode0.Command = new AddDiagramCommand(cxtmNodeSolution, cxtmNodeSolutionNode0);
            cxtmNodeSolution.Items.Add(cxtmNodeSolutionNode0);

            MenuItem cxtmNodeSolutionNode1 = new MenuItem();
            cxtmNodeSolutionNode1.Header = "Add Package";
            cxtmNodeSolutionNode1.Command = new AddPackageCommand(cxtmNodeSolution, cxtmNodeSolutionNode1);
            cxtmNodeSolution.Items.Add(cxtmNodeSolutionNode1);

            MenuItem cxtmNodeSolutionNode2 = new MenuItem();
            cxtmNodeSolutionNode2.Header = "Add Interface";
            cxtmNodeSolutionNode2.Command = new AddInterfaceCommand(cxtmNodeSolution, cxtmNodeSolutionNode2);
            cxtmNodeSolution.Items.Add(cxtmNodeSolutionNode2);

            MenuItem cxtmNodeSolutionNode3 = new MenuItem();
            cxtmNodeSolutionNode3.Header = "Add Class";
            cxtmNodeSolutionNode3.Command = new AddClassCommand(cxtmNodeSolution, cxtmNodeSolutionNode3);
            cxtmNodeSolution.Items.Add(cxtmNodeSolutionNode3);

            return cxtmNodeSolution;
        }

        private static ContextMenu CreateClassTreeNodeContextMenu()
        {
            ContextMenu cxtmNodeSolution = new ContextMenu();
            MenuItem cxtmNodeSolutionNode1 = new MenuItem();
            cxtmNodeSolutionNode1.Header = "Add Property";
            cxtmNodeSolutionNode1.Command = new AddPropertyCommand(cxtmNodeSolution, cxtmNodeSolutionNode1);
            cxtmNodeSolution.Items.Add(cxtmNodeSolutionNode1);

            MenuItem cxtmNodeSolutionNode2 = new MenuItem();
            cxtmNodeSolutionNode2.Header = "Add Method";
            cxtmNodeSolutionNode2.Command = new AddMethodCommand(cxtmNodeSolution, cxtmNodeSolutionNode2);
            cxtmNodeSolution.Items.Add(cxtmNodeSolutionNode2);
            return cxtmNodeSolution;
        }

        private static ContextMenu CreatePackageTreeNodeContextMenu()
        {
            ContextMenu cxtmNodeSolution = new ContextMenu();

            MenuItem cxtmNodeSolutionNode0 = new MenuItem();
            cxtmNodeSolutionNode0.Header = "Add Diagram";
            cxtmNodeSolutionNode0.Command = new AddDiagramCommand(cxtmNodeSolution, cxtmNodeSolutionNode0);
            cxtmNodeSolution.Items.Add(cxtmNodeSolutionNode0);

            MenuItem cxtmNodeSolutionNode1 = new MenuItem();
            cxtmNodeSolutionNode1.Header = "Add Package";
            cxtmNodeSolutionNode1.Command = new AddPackageCommand(cxtmNodeSolution, cxtmNodeSolutionNode1);
            cxtmNodeSolution.Items.Add(cxtmNodeSolutionNode1);

            MenuItem cxtmNodeSolutionNode2 = new MenuItem();
            cxtmNodeSolutionNode2.Header = "Add Interface";
            cxtmNodeSolutionNode2.Command = new AddInterfaceCommand(cxtmNodeSolution, cxtmNodeSolutionNode2);
            cxtmNodeSolution.Items.Add(cxtmNodeSolutionNode2);

            MenuItem cxtmNodeSolutionNode3 = new MenuItem();
            cxtmNodeSolutionNode3.Header = "Add Class";
            cxtmNodeSolutionNode3.Command = new AddClassCommand(cxtmNodeSolution, cxtmNodeSolutionNode3);
            cxtmNodeSolution.Items.Add(cxtmNodeSolutionNode3);

            return cxtmNodeSolution;
        }
    }
}
